<script type="text/javascript">
 $(function(){
 	$.post("tellerManage/getRoleByTeller",getRoleByTeller,"json")
}); 
 function getRoleByTeller(json){
	 if(json.statusCode==DWZ.statusCode.error){
		navTabAjaxDone(json)
		return ;
	}
	 var isSet=json.map.isSet;
	 var noSet=json.map.noSet;
	// alert(isSet.length)
	 var optiona="";
	 var optionb="";
	 for(var i=0;i<isSet.length;i++){
		 var value=isSet[i].roleId+","+isSet[i].sysId
		 optiona+="<option value="+value+">"+isSet[i].roleName+"</option>"
	 }
	 for(var i=0;i<noSet.length;i++){
		 var value=noSet[i].roleId+","+noSet[i].sysId
		 optionb+="<option value="+value+">"+noSet[i].roleName+"</option>"
	 }
	 $("input[name='userNo']").val(json.user.userNo)
	 $("input[name='userId']").val(json.user.userId)
	 $("input[name='userName']").val(json.user.userName)
	 $("#select2").html(optionb)
	 $("#select1").html(optiona);
 }
//移到右边
$('#removeToRight').click(function(){
	//先判断是否有选中
	if(!$("#select1 option").is(":selected")){			
		alertMsg.warn("请选择需要移动的选项")
	}
	//获取选中的选项，删除并追加给对方
	else{
		alertMsg.confirm("是否确定", {
    		okCall: function(){
    			var userNo=$("input[name='userNo']").val();
    			var v=$('#select1 option:selected').val().split(",");
    			var sysId=v[1];
    			var roleId=v[0];
    			//alert(sysId+","+roleId);
    			 $('#select1 option:selected').appendTo('#select2');
    			$.post("roleManage/commitPersonalSet",{sysId:sysId,roleId:roleId,userNo:userNo,sign:"0"},function(json){
    				
    			},"json"); 
    		}
    	});
	}	
});
	
//移到左边
$('#removeToLeft').click(function(){
	//先判断是否有选中
	if(!$("#select2 option").is(":selected")){			
		alertMsg.warn("请选择需要移动的选项")
	}
	else{
		alertMsg.confirm("是否确定", {
    		okCall: function(){
		var userNo=$("input[name='userNo']").val();
		var v=$('#select2 option:selected').val().split(",");
		var sysId=v[1];
		var roleId=v[0];
		//alert(sysId+","+roleId);
		$('#select2 option:selected').appendTo('#select1');
		$.post("roleManage/commitPersonalSet",{sysId:sysId,roleId:roleId,userNo:userNo,sign:"1"},function(json){
			
		},"json");
    		}
    	});
	}
});
	
//全部移到右边
$('#add_all').click(function(){
	alertMsg.confirm("是否确定", {
		okCall: function(){
	var options=new Array();
	options.push("0,0");
	//获取全部的选项,删除并追加给对方
	$('#select1 option').each(function(){
		//alert($(this).val())
		options.push($(this).val());
	});
	var userNo=$("input[name='userNo']").val();
	$.ajax({
		url:"roleManage/commitPersonalSet",
		 dataType:'json',
		 type:"post",
	 	 traditional:true,
	 	 data:{
	 		 "userNo":userNo,
	 		 "sign":"0",
	 		 "options":options,
	 	 },
	 	success:function(json){
			
		}
	})
	$('#select1 option').appendTo('#select2');
		}
	});
});

//全部移到左边
$('#remove_all').click(function(){
	alertMsg.confirm("是否确定", {
		okCall: function(){
	var options=new Array();
	options.push("0,0");
	//获取全部的选项,删除并追加给对方
	$('#select2 option').each(function(){
		//alert($(this).val())
		options.push($(this).val());
	});
	var userNo=$("input[name='userNo']").val();
	$.ajax({
		url:"roleManage/commitPersonalSet",
		 dataType:'json',
		 type:"post",
	 	 traditional:true,
	 	 data:{
	 		 "userNo":userNo,
	 		 "sign":"1",
	 		 "options":options,
	 	 },
	 	success:function(json){
			
		}
	})
	$('#select2 option').appendTo('#select1');
}
});
});
	
//双击选项
$('#select1').dblclick(function(){ //绑定双击事件
	//获取全部的选项,删除并追加给对方
	var userNo=$("input[name='userNo']").val();
	var v=$("option:selected",this).val().split(",");
	var sysId=v[1];
	var roleId=v[0];
	//alert(sysId+","+roleId);
	$("option:selected",this).appendTo('#select2'); //追加给对方
	$.post("roleManage/commitPersonalSet",{sysId:sysId,roleId:roleId,userNo:userNo,sign:"0"},function(json){
		
	},"json");
});
	
//双击选项
$('#select2').dblclick(function(){
	var userNo=$("input[name='userNo']").val();
	var v=$("option:selected",this).val().split(",");
	var sysId=v[1];
	var roleId=v[0];
	//alert(sysId+","+roleId);
	$("option:selected",this).appendTo('#select1'); //追加给对方
	$.post("roleManage/commitPersonalSet",{sysId:sysId,roleId:roleId,userNo:userNo,sign:"1"},function(json){
		
	},"json");	
});

</script>
<div class="pageContent">
	<form method="post" action="tellerManage/updateTeller" class="pageForm required-validate" onsubmit="return validateCallback(this,dialogAjaxDone);">
		<div class="pageFormContent" >
			<div id=userNo>
			<p >
				<label>柜员编号：</label>
				<input name="userNo"  type="text" size="30" class=" " readonly="readonly"/>
				
			</p>
			</div>
			<p>
				<label>柜员名称：</label>
				<input  name="userName"  type="text" size="30" readonly="readonly" />
				<input  name="userId"  type="hidden" size="30" class="" />
			</p>
		
		
		</div>
		<div id="selectbox">
<div class="select-bar">

<label>当前角色：</label>
    <select multiple="multiple" id="select1">
     
    </select>
    
</div>

<div class="btn-bar">
    <p><span id="removeToRight"><input type="button" class="btn" value=">" title="移动选择项到右侧"/></span></p>
    <p><span id="add_all"><input type="button" class="btn" value=">>" title="全部移到右侧"/></span></p>
    <p><span id="removeToLeft"><input type="button" class="btn" value="<" title="移动选择项到左侧"/></span></p>
    <p><span id="remove_all"><input type="button" class="btn" value="<<" title="全部移到左侧"/></span></p>
</div>
<div class="select-bar">
	<label>未添加角色：</label>
    <select multiple="multiple" id="select2" ></select>
</div>	
</div>
	</form>
</div>